/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			pgcolor.h
  \date			Jun 2012
  \author		TNick

  \brief		Contains the definition for PgColor class


*//*


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read COPYING and README files in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef __PGCOLOR_INC__
#define __PGCOLOR_INC__
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<QRgb>
#include	<cpg/logic/pgcharacteristic.h>
#include	<bytebuffer.h>

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

namespace	cpg		{

class	PgCtx;

/**
*	@brief	Represents a custom color in a CpgDoc
*/
class PgColor		: public PgCharacteristic		{
	BBM_TRACK( PgColor );

	//
	//
	//
	//
	/*  DEFINITIONS    ----------------------------------------------------- */


public:



#	define	colorQtPgExchange	0x1000
#	define	colorFromPgToQt(c)	(Qt::GlobalColor)(c+colorQtPgExchange)
#	define	colorFromQtToPg(c)	(PgColor::Id)(c-colorQtPgExchange)



	/**
	*	@brief	representation of a color in Play-Ground
	*
	*	Special codes are negative; zero and positive numbers are used
	*	as indices in the CpgDoc hosted array of colors (only the document
	*	hosts a PgColor, the other entities use Id's.
	*
	*	To convert between a Id and a Qt::GlobalColor use the
	*	colorFromPgToQt macro; the other way arround is done using
	*	colorFromQtToPg.
	*/
	enum			Id				{

		/* predefined (named) colors */
		BLACK = Qt::black-colorQtPgExchange,
		WHITE = Qt::white-colorQtPgExchange,
		DARKGRAY = Qt::darkGray-colorQtPgExchange,
		GRAY = Qt::gray-colorQtPgExchange,
		LIGHTGRAY = Qt::lightGray-colorQtPgExchange,
		RED = Qt::red-colorQtPgExchange,
		GREEN = Qt::green-colorQtPgExchange,
		BLUE = Qt::blue-colorQtPgExchange,
		CYAN = Qt::cyan-colorQtPgExchange,
		MAGENTA = Qt::magenta-colorQtPgExchange,
		YELLOW = Qt::yellow-colorQtPgExchange,
		DARKRED = Qt::darkRed-colorQtPgExchange,
		DARKGREEN = Qt::darkGreen-colorQtPgExchange,
		DARKBLUE = Qt::darkBlue-colorQtPgExchange,
		DARKCYAN = Qt::darkCyan-colorQtPgExchange,
		DARKMAGENTA = Qt::darkMagenta-colorQtPgExchange,
		DARKYELLOW = Qt::darkYellow-colorQtPgExchange,

		/* special codes */
		BYLAYER = PgCharacteristic::BYLAYER,
		BYBLOCK = PgCharacteristic::BYBLOCK,

		FOREGROUND = -3,
		BACKGROUND = -4


	};


	/**
	*	@brief	the container for the list of colors (in a document, for example)
	*/
	typedef	QList<Id>			List;


	/*  DEFINITIONS    ===================================================== */
	//
	//
	//
	//
	/*  DATA    ------------------------------------------------------------ */

private:


	/**
	*	@brief	the color value
	*/
	QRgb				color_;


	/*  DATA    ============================================================ */
	//
	//
	//
	//
	/*  FUNCTIONS    ------------------------------------------------------- */

public:


	/**
	*	@brief	constructor;
	*/
	PgColor					( CpgDoc * doc );


	/**
	*	@brief	destructor;
	*/
	~PgColor				( void );


	/**
	*	@brief	get the name that coresponds to given id
	*/
	inline QRgb				rgb			( void )
	{ return color_; }


	/**
	*	@brief	get the name that coresponds to given id
	*/
	inline void				setRgb		( QRgb new_val )
	{ color_ = new_val; }


	/**
	*	@brief	clone this characteristic in target ocument
	*/
	PgColor *				clone		( CpgDoc * destin, int & idx );





	/* ******************************************************************* */
	/** @name 	Management methods                                         */
	/* ******************************************************************* */
	///@{


	/**
	*	@brief	tell if the code is within valid range
	*/
	static bool				isIdValid		( CpgDoc * doc, int id );


	/**
	*	@brief	get the QColor for a particular code
	*/
	static QColor			qtColor			(
			PgCtx &				ctx,
			int					id
			);


	/**
	*	@brief	save a color as a XML attribute for provided element
	*/
	static void				asXML			(
			PgCtx &					ctx,
			int						id,
			BBlocks::ByteBuffer *	dest
			);


	/**
	*	@brief	copies a color from source document to target document
	*
	*	@return	the id to be used in destination document
	*/
	static int				copy			(
			CpgDoc *				source,
			CpgDoc *				destin,
			int					value
			);



	///@}
	/* ******************************************************************* */



	/* ******************************************************************* */
	/** @name 	String related nethods                                     */
	/* ******************************************************************* */
	///@{


protected:


	/**
	*	@brief	get the name that coresponds to given id
	*/
	static QString			nameForId		( Id id );


	/**
	*	@brief	get the names and coresponding id for all codes
	*/
	static void				nameAndId		(
			QStringList &			name_list,
			QList<int> &			id_list
			);


public:


	/**
	*	@brief	get the names of the colors in the list
	*/
	static QStringList		names			( CpgDoc * doc, const List & list );


	/**
	*	@brief	get the string representation for a given id
	*/
	static QString			asString		( CpgDoc * doc, int id );


	///@}
	/* ******************************************************************* */


	/*  FUNCTIONS    ======================================================= */
	//
	//
	//
	//

};	/*	class PgColor	*/

/*  CLASS    =============================================================== */
//
//
//
//

}	//	namespace	cpg

#endif // __PGCOLOR_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
